$("#fh").click(function () {
       layer.msg("返回上一级页面")
})
$("#sx").click(function () {
    window.location = 'operationLog.html';
})

var operationLogtabletableI = null;
function  operationLogtableRefre(){
    operationLogtabletableI.reload('operationLogtableId');
}
layui.use(['table', 'laydate','form'], function(){
        var table = layui.table,
        laydate = layui.laydate,
        form = layui.form;

        laydate.render({
                elem: '#rq', //指定元素
        });


    operationLogtabletableI = table.render({
                elem: '#test',
                url:'/operationLog/getAll',
                id:'operationLogtableId',
                page:{
                    layout:['count','prev','page','next','limit'],
                    groups:2,
                    limit:10,
                    limits:[10,15,20]

                },
                cols: [[
                        {type: 'checkbox',width: 50},
                        {field:'operationLogId', width: 70, title: '序号'},
                        {field:'administratorName', width: 250, title: '管理员名称',align:'center'},
                        {field:'actionListName', width: 250, title: '操作的列表',align:'center'},
                        {field:'executionTime', width: 250, title: '执行时间',align:'center'},
                        {field:'operationType', title: '操作类型',  width: 250,align:'center'},
                        {field:'operationRemarks', title: '备注',  width: 250,align:'center'},
                        {fixed: '', title:'操作', toolbar: '#barDemo',align:'center'}
                ]],
                toolbar:'#toolbarDemo',
                skin: 'line',
                parseData:function (res){
                        return{
                                "code":res.code, // 解析接口状态
                                "msg": res.msg, // 解析提示文本
                                "count": res.count, // 解析总条数
                                "data": res.data // 解析数据列表
                        };
                }
        });

        table.on('tool(test)', function(obj){ // 双击 toolDouble
                data = obj.data;
                //console.log(obj)
                if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(){
                        // layer.close(index);
                        $.ajax({
                            type:"post",
                            url:'/operationLog/del',
                            data: {"operationLogId":data.operationLogId},
                            dataType:'json',
                            success:function (res) {
                                if (res.state == 200){
                                    layer.msg(res.msg,{time:500,icon:6})
                                    operationLogtableRefre();
                                }
                                else {
                                    layer.msg(res.msg,{time:500,icon:5})
                                }
                            },
                            error:function(e){
                                console.log("异常");

                            }

                        })

                    });
                }

        });
        table.on('toolbar(test)',function (obj) {
            data = obj.data;
            if(obj.event == 'plsc'){
                // alert("批量删除");
                //    批量删除，
                    //获得表格CheckBox已经选中的行的信息
                    var checkStatus = table.checkStatus('operationLogtableId'),
                        //返回行的value
                        data = checkStatus.data;

                    let arr = [];
                    for (i=0;i<data.length;i++){

                        arr.push( data[i].operationLogId);
                    }

                    // console.log(arr);
                    if (arr.length > 0) {
                        layer.confirm('确定删除选中的用户？', {icon: 6, title: '提示信息'}, function () {

                            console.log(data[0].operationLogId);
                            $.ajax({
                                type:"post",
                                url:'/operationLog/delAll',
                                data: {"arr":arr},
                                dataType:'json',
                                success:function (res) {
                                    if (res.state == 200){
                                        layer.msg(res.msg,{time:500,icon:6})
                                        operationLogtableRefre();
                                    }
                                    else {
                                        layer.msg(res.msg,{time:500,icon:5})
                                    }
                                },
                                error:function(e){
                                    console.log("异常");

                                }

                            })

                        })
                    } else {
                        layer.msg("请选择需要删除的行");
                    }
            }
        })

        form.on('submit(go)',function (d){
                d = d.field;
                console.log(d);
                table.reload('operationLogtableId',{
                        where:{
                            administratorName:d.administratorName,
                            actionListName:d.actionListName,
                            operationType:d.operationType,
                            executionTime:d.executionTime
                        }
                });
        })

});
